/**
 * 
 */
package signalprocessing;

import ikelib.Variance;

import java.util.LinkedList;

import javax.swing.JOptionPane;


/**
 * @author ikechan
 *
 */
public class PanelDynamicRangeTemp extends PanelTemperature{
	public PanelDynamicRangeTemp(){
		super();
	}
	/**
	 *  1つのＣＨのグラフエリアを生成する。
	 * @param Panel_Channels
	 * @param id
	 */
	public void addData(Integer[] ids) {

		//	if(subid ==0) return;
		DecimationPeriod = 60;
		int xid = getXid();
		int sampleratex = getRawSampleRate(xid);
		if(sampleratex<=0) return;
		double[] xdat=getChannelRawData(xid);
		xdat = decimate(xdat,sampleratex*DecimationPeriod);
		LinkedList<String> names = new LinkedList<String>();

		LinkedList<double[]> datas = new LinkedList<double[]>();
		for(int i=0;i<ids.length;i++){
			int id = ids[i];
			int samplerate=getRawSampleRate(id);;
			if(samplerate<=0) return;
			double[] data = null;
			if(cbShowDigit.isSelected()){
				data = getChannelRawData(id,1.0);
			}
			else{
				data = getChannelRawData(id);
			}
			if(data == null || xdat==null){
				//System.out.println("fail to getChannelRawData: SignalProcessingPain " + id + subid);
				String mes=new String("No data found for CH = ");
				if(data == null) mes +=  String.format(" %04x", id);
				if(xdat == null) mes +=  String.format(" %04x", getXid());
				JOptionPane.showMessageDialog(null, "No data found " + mes , mes,  JOptionPane.ERROR_MESSAGE, null);
				return;
			}
			//if(samplerate != 1){
			//data = decimate(data,samplerate*DecimationPeriod);
			// RMSノイズ計算
			data = Variance.calc(data, samplerate*DecimationPeriod, true, true);
			
			//}
			
			
			
			datas.add(data);
			String name = new String(String.format("%04X", id));
			names.add(name);
		}
		PlotCollection.addChannelPanel(xid, ids ,names, datas, 1,xdat);
		//addChannelPanel(Panel_Channels,xid, ids ,names, datas, 1,xdat);
	}


}
